package net.zjitc.pojo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
public class BillResponse {
    private Long customerId;
    private String customerName;
    private String customerIdCard;
    private List<BillItem> billItemList;
    private BigDecimal discountPrice;//优惠价格
    private BigDecimal totalPrice;


    public static BillResponse convertFromBill(Bill bill,String customerName,String customerIdCard){
        BillResponse billResponse=new BillResponse();
        billResponse.customerId=bill.getCustomerId();
        billResponse.customerName=customerName;
        billResponse.customerIdCard=customerIdCard;
        billResponse.billItemList=bill.getBillItemList();
        BigDecimal discountPrice =BigDecimal.valueOf(0);
        for (BillItem billItem:billResponse.billItemList){
            discountPrice.add(billItem.getPrice().subtract(billItem.getDiscountPrice()));
        }
        billResponse.totalPrice=bill.getTotalPrice();
        billResponse.discountPrice=discountPrice;
        return billResponse;
    }
}
